package com.sy.controller;

import com.sy.dto.JsonResult;
import com.sy.entity.Media;
import com.sy.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author King
 * @Date 2021/1/19 10:55
 */
@RestController
@RequestMapping("Media")
public class MediaController {

    @Autowired
    private MediaService service;

    @RequestMapping("show")
    public JsonResult showMedia(){
        JsonResult result = new JsonResult();
        List<Media> media = service.selectVideoSix();
        result.setData(media);
        return result;
    }

    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public JsonResult getMediaById(@PathVariable("id") Integer id){
        Media media = service.selectById(id);
        JsonResult result = new JsonResult();
        result.setData(media);
        return result;
    }

    @RequestMapping(method = RequestMethod.GET,params = "vName")
    public JsonResult getSortByMonthly(HttpServletRequest req){
        JsonResult result = new JsonResult();
        String vName = req.getParameter("vName");
        System.out.println("==>:"+vName);
        List<Media> search = service.getSearch(vName);
//        System.out.println("search"+search);
        result.setData(search);
        return result;
    }

}
